package org.dev.vlp.controller;

import org.dev.vlp.bean.JsonResponse;
import org.dev.vlp.constants.Roles;
import org.dev.vlp.dto.PublishMomentParam;
import org.dev.vlp.interceptor.RequiredPermission;
import org.dev.vlp.service.MomentService;
import org.dev.vlp.vo.MomentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * Description
 * Param
 * return
 * Author:86184
 * Date: 2023/1/11
 */
@RestController
@RequestMapping("/moment")
@RequiredPermission({Roles.ROLE_USER})
public class MomentController extends BaseController {
    @Autowired
    private MomentService momentService;


    @PostMapping(value = "/{momentId}")
    public JsonResponse<MomentVo> getMomentDetail(@PathVariable("momentId") int momentId) {

        return JsonResponse.success(momentService.getMomentDetail(momentId));
    }

    @PutMapping
    public JsonResponse<Object> publishMoment(@Valid @RequestBody PublishMomentParam request) {

        momentService.publishMoment(request,(int)getUid());

        return JsonResponse.success();
    }

    @DeleteMapping("/{momentId}")
    public JsonResponse<Object> deleteMoment(@PathVariable("momentId") int momentId) {

        momentService.deleteMoment(momentId,(int)getUid());
        return JsonResponse.success();
    }
}
